package com.ys.controller.web.flow;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ys.entity.flow.YspModel;
import com.ys.vo.W;

import lombok.AllArgsConstructor;
import lombok.Data;

@Controller
@RequestMapping("/web/flow/yspModel")
public class WebYspModelController {
	
	/**
	 * 新增
	 */
	@GetMapping("/toAdd")
	public String toAdd(Model model){
		
		return "flow/yspModel/toAdd";
	}
	
	/**
	 * 在线设计
	 */
	@GetMapping("/toDesign")
	public String toDesign(Model model, Long id){
		
		if (id == null) {
			return W.error(model, "ID不能为空");
		}
		
		YspModel entity = new YspModel().setId(id).queryFirst();
		String info = entity.getInfo();
		ToDesignDto dto = new ToDesignDto(id, info);

		model.addAttribute("dto", dto);
		return "flow/yspModel/toDesign";
	}
	@Data
	@AllArgsConstructor
	private static class ToDesignDto{
		private Long id; // 
		private String info; // 
	}
	
	/**
	 * 部署
	 */
	@GetMapping("/toDeploy")
	public String toDeploy(Model model, Long id){
		
		if (id == null) {
			return W.error(model, "ID不能为空");
		}
		
		YspModel entity = new YspModel().setId(id).queryFirst();
		String name = entity.getName();
		Integer versionCurrent = entity.getVersionLatest();
		Integer versionNext = versionCurrent + 1;
		ToDeployDto dto = new ToDeployDto(id, name, versionCurrent, versionNext);

		model.addAttribute("dto", dto);
		return "flow/yspModel/toDeploy";
	}
	@Data
	@AllArgsConstructor
	private static class ToDeployDto{
		private Long id; // 
		private String name; // 
		private Integer versionCurrent; //
		private Integer versionNext; // 
	}
}
